package com.example.library_room.converter

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type

class StringTypeConverter {
    @TypeConverter
    fun strToList(value: String?): List<String>? {
        if (value == null){
            return mutableListOf()
        }

        val listType: Type = object : TypeToken<List<String?>?>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun listToStr(value: List<String>?): String {
        if (value.isNullOrEmpty()){
            return Gson().toJson(mutableListOf<String>())
        }
        return Gson().toJson(value)
    }

}